package com.education.ai.repository;

import com.education.ai.entity.ExamRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 考试记录数据访问接口
 */
@Repository
public interface ExamRecordRepository extends JpaRepository<ExamRecord, Long> {
    
    /**
     * 根据学生ID查询考试记录
     */
    List<ExamRecord> findByStudentId(String studentId);
    
    /**
     * 根据学生ID列表查询考试记录
     */
    List<ExamRecord> findByStudentIdIn(List<String> studentIds);
    
    /**
     * 查询学生的平均成绩
     */
    @Query("SELECT AVG(e.chinese), AVG(e.math), AVG(e.english), " +
           "AVG(e.politics), AVG(e.history), AVG(e.geography), " +
           "AVG(e.physics), AVG(e.chemistry), AVG(e.biology) " +
           "FROM ExamRecord e WHERE e.studentId = :studentId")
    List<Object[]> findAverageScoresByStudentId(@Param("studentId") String studentId);
} 